#ifndef INCLUDED_TASK_H
#define INCLUDED_TASK_H

#include <string>
#include <set>
#include "basetask.h"
#include "win32.h"

//

namespace tinkle {

class TaskManager;
    
class Task : public BaseTask {
public:
    Task(BaseTask *parent);
    virtual ~Task();
    enum {
        TASK_BLOCKED = -1,
        TASK_INIT,
        TASK_READY,
        TASK_ABORTED,
        TASK_DONE
    };
    // each task should have a unique id. 
    uint32_t Id() const;
    // get the task's state
    bool IsDone() const;

    // invoke Start() to start a task, at the same time the task will register
    // to the task manager
    void Start();
    // When the task has started, it maybe can not finish the work at
    // once. There you can call Process() to have the task process again
    virtual void Process();
    virtual bool HasNetworkEvent() const;

protected:
    // codes in ProcessInit will be run only once, you can put some initialized
    // codes here.
    virtual void ProcessInit();
    // codes in ProcessReady will be run more than once, until the task has
    // been finished or aborted
    virtual void ProcessReady();

private:
    // task's initialize code
    void Initialize();

    uint32_t _id;
    int _state;
    bool _hasNetworkEvent;

    static uint32_t _unique_id_seed;
};

}

#endif